package com.mt.roll.wms.controller;

import com.mt.roll.core.constants.CommonConstant;
import com.mt.roll.core.dal.entity.EquipmentRecipe;
import com.mt.roll.core.params.IdParam;
import com.mt.roll.core.utils.CodeGeneratorHelper;
import com.mt.roll.core.vo.R;
import com.mt.roll.wms.params.EquipmentRecipeParam;
import com.mt.roll.wms.params.EquipmentRecipeQueryParam;
import com.mt.roll.wms.params.RecipeActiveSend;
import com.mt.roll.wms.params.RecipeListParam;
import com.mt.roll.wms.service.EquipmentRecipeService;
import com.mt.roll.wms.vo.EquipmentRecipeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.groups.Default;
import java.util.List;

/**
 * @Desc: ""
 * @Author: caixiang
 * @DATE: 2020/12/29 19:51
 */
@RestController
@RequestMapping(CommonConstant.API_MODULE_WMS + "equipment-recipe")
@Slf4j
@Api(value = "设备配方配置", tags = "设备配方配置", hidden = false)
public class EquipmentRecipeController {

    @Autowired
    private EquipmentRecipeService equipmentRecipeService;

    @PostMapping(value = "findAllByEquipmentTypeAndRecipeName")
    @ApiOperation(value = "1.依据设备id 和 设备配方名 获取配方列表;;2.依据设备id 获取配方列表")
    private R<List<EquipmentRecipe>> findByName(@Validated({Default.class}) @RequestBody EquipmentRecipeQueryParam equipmentRecipeQueryParam) {
        return equipmentRecipeService.findAllByEquipmentTypeAndRecipeName(equipmentRecipeQueryParam);
    }

    @PostMapping(value = "updateRecipeListByToolName")
    @ApiOperation(value = "模拟EAP=>MES 发送设备配方列表")
    private R<Boolean> updateRecipeListByToolName(@Validated({Default.class}) @RequestBody RecipeListParam recipeListParam) {
        return equipmentRecipeService.updateRecipeListByToolName(recipeListParam);
    }

    @PostMapping(value = "getEquipmentRecipeCode")
    @ApiOperation(value = "获取自动生成的设备配方编码")
    private R<String> getEquipmentRecipeCode() {
        return R.ok(CodeGeneratorHelper.getEquipmentRecipeCode());
    }

    @PostMapping(value = "create")
    @ApiOperation(value = "新建设备配方")
    private R<Boolean> create(@Validated({Default.class}) @RequestBody EquipmentRecipeParam equipmentRecipeParam) {
        return equipmentRecipeService.create(equipmentRecipeParam);
    }

    @PostMapping(value = "update")
    @ApiOperation(value = "更新设备配方  依据ID 修改（传需要改的内容或者都传都行。）")
    private R<Boolean> update(@Validated({Default.class}) @RequestBody EquipmentRecipeParam equipmentRecipeParam) {
        //update 的时候注意不要传 version ..让他自增。
        return equipmentRecipeService.update(equipmentRecipeParam);
    }

    @PostMapping(value = "delete")
    @ApiOperation(value = "删除设备配方 （依据ID 删除）")
    private R<Boolean> delete(@Validated @RequestBody IdParam idParam) {
        //todo 注意 这里删除设备配方的时候要连带 这个配方下面的参数 也一并删除。
        return equipmentRecipeService.delete(idParam);
    }

    @PostMapping(value = "findById")
    @ApiOperation(value = "依据设备配方id查询")
    private R<EquipmentRecipeVo> findById(@Validated({Default.class}) @RequestBody IdParam idParam) {
        return equipmentRecipeService.findById(idParam);
    }


    @PostMapping(value = "simulationForActiveRecipe")
    @ApiOperation(value = "模拟设备发送active recipe")
    private R<Boolean> simulationForActiveRecipe(@Validated({Default.class}) @RequestBody RecipeActiveSend recipeActiveSend) {
        return equipmentRecipeService.simulationForActiveRecipe(recipeActiveSend);
    }


    //设备配方参数 增删查改
    //todo 设备配方参数 还没做 有疑惑，原型图（配方 不就一个配方名吗 为什么还有 配方参数 这张表）；；表T_EQUIPMENT_RECIPE_PARAMETER 中 为什么会有EQUIPMENT_PARAMETER_ID 这个字段

}